<?php
	class Ykienkhachhang extends CI_Controller
    {
        public function __construct() {
            parent::__construct();
            $this->load->helper('url');
        }
        
        public function index()
        {
            $this->load->model('Nkdefault', 'default');            
            $this->load->model('admin/managethongbao', 'thongbao');      
            $temp['title'] = "Ý kiến khách hàng";
            $temp['template'] = 'ykien';
            $temp['data']['info'] = "Ý kiến khách hàng";
            $temp['danhmuc']['menu'] = $this->default->loadDanhMuc();
            $temp['danhmuc']['currentItem'] = 'ykienkhachhang';
            //load thong bao
            $thongbao = $this->thongbao->LoadThongBao(null, null, 1, 0);
            if(!empty($thongbao)) $temp['thongbao'] = $thongbao->result_array();   
            $temp['online'] = $this->useronline->countOnline();   
            
            $this->load->view('template/layout', $temp);
        }
        
        public function GoiYKien()
        {
            $hoten = $this->input->post('inputName');
            $diachi = $this->input->post('inputAddress');
            $phone = $this->input->post('inputPhone');
            $email = $this->input->post('inputEmail');
            $description = $this->input->post('inputDescription');
            if($email != "")
            {
                $this->load->model('ykien');
                $this->ykien->HoTen = $hoten;
                $this->ykien->DiaChi = $diachi;
                $this->ykien->SoDienThoai = $phone;
                $this->ykien->Email = $email;
                $this->ykien->NoiDungGopY = $description;
                $result = $this->ykien->ThemYKienKhachHang();
                if($result)
                {
                    $this->load->library('email');
                    $this->email->from($email, $hoten);
                    $this->email->to('son.phamhoang89@hotmail.com');
                    $this->email->subject('Ý kiến khách hàng');
                    $this->email->message($description);
                    if($this->email->send())
                    {
                        echo 'true';
                    }
                    else
                    {
                        echo $this->email->print_debugger();
                    }
                }               
                else
                {
                    echo 'false';
                }
            }
        }
    }
?>